home *** CD-ROM | disk | FTP | other *** search
- Path: fido.asd.sgi.com!austern
- From: lars.farm@nts.mh.se (Lars Farm)
- Newsgroups: comp.std.c++
- Subject: Re: sample auto_ptr template
- Date: 12 Apr 1996 08:53:43 PDT
- Organization: pv
- Approved: austern@isolde.mti.sgi.com
- Message-ID: <AD9409799668E161@sleipner.nts.mh.se>
- References: <009A04DA6A831C40.49800EAC@ittpub.nl> <bill-0504961003150001@bgibbons.vip.best.com> <4k4noe$igl@jabba.lehman.com> <bill-0804960932250001@bgibbons.vip.best.com> <4kcr2d$p03@jabba.lehman.com> <KANZE.96Apr10111407@gabi.gabi-soft.fr>
- NNTP-Posting-Host: isolde.mti.sgi.com
- Content-Type: text/plain; charset=iso-8859-1
- Content-Transfer-Encoding: 8bit
- X-Original-Date: Fri, 12 Apr 1996 13:22:01 +0200
- X-Auth: PGPMoose V1.1 PGP comp.std.c++
- iQBVAwUBMW58iEy4NqrwXLNJAQEQDwIAzaJb+tInP/XHgDpMHdkY7YjTAKKxKz+k
- J37umZG3oGmGc3ReHNq5R5TSg1Loo1YHKGNWNhvdlHPwrnNk0qHpqQ==
- =lO2z
- Originator: austern@isolde.mti.sgi.com
-
- In article <KANZE.96Apr10111407@gabi.gabi-soft.fr>,
- kanze@gabi-soft.fr (J. Kanze) wrote:
-
- >I believe that John Skaller had a proposal with something like six
- >different pointer types. The committee found this a little too
-
- He said a while ago that he proposed two classes(*). (1) auto_ptr for
- lifetime control within a block (no copy/assign) and (2) a ref counted
- class for shared objects. There is a need for both but only one was
- accepted and that is the real problem.
-
- auto_ptr<> is slowly being mutated into a mixture of the two classes. It
- has moved away from its original goal and is becoming a cheap shared_ptr<>.
- This requires very strange and disturbing use of op=/copy.
-
- void f( auto_ptr<X> x ) { ...will delete x }
-
- // promise: x const, x will _not_ change, x will _not_ become invalid
- void g( const auto_ptr<X>&x ) {
- // ... x ok
- f(x);
- // ... oops
- }
- void h() {
- auto_ptr<X> p( new X );
- // p valid
- g(x);
- // p bad. Undetected by the compiler because the standard
- // library class auto_ptr subverted the C++ type system
- }
-
- IMHO the only reasonable solution is to have two classes. If the committee
- only accepts one then users will have to write the other. That's ok, as
- long as it is obvious that auto_ptr isn't a general purpose smart_ptr. With
- the current weird auto_ptr copy/op= perhaps users will have to write both
- the original and the ref counted class on their own. Or worse, they will
- actually use auto_ptr as if it was the rejected ref_counted ptr. This is a
- reasonable assumption because auto_ptr is the only standard smart ptr and
- users should be allowed to assume it is safe. It would be safe with private
- op=/copy as the original.
-
- When designing a class for mass consumption it should not only support the
- intended idioms. It should also prevent missuse in common situations. The
- original does that. The current auto_ptr doesn't.
-
- Please reconsider John Max Skallers original proposal.
-
- (*) he has also mentioned other smart pointers here. holding arrays -
- block/ref-counted. copying pointers and cloning pointers using varying
- implementation techniques but AFAIK they were never proposed as standard
- classes.
-
- --
- Lars Farm, lars.farm@nts.mh.se
- ---
- [ comp.std.c++ is moderated. To submit articles: Try just posting with your
- newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
- comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
- Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
- Comments? mailto:std-c++-request@ncar.ucar.edu
- ]
-